package hu.mapro.flang.gwt.client.ui.exercise;

import hu.mapro.flang.gwt.client.ui.menu.ManageMenuGroup;
import hu.mapro.flang.gwt.domain.client.AutoBeans.BookProxy;
import hu.mapro.flang.gwt.domain.client.AutoBeans.BookFields;
import hu.mapro.flang.gwt.domain.client.AutoBeans.Messages;
import hu.mapro.gwtui.client.app.MenuItems;
import hu.mapro.gwtui.client.app.Workspace;
import hu.mapro.gwtui.gxt.client.LabelProviders;
import hu.mapro.gwtui.gxt.client.ModelKeyProviders;
import hu.mapro.gwtui.gxt.client.form.FormFieldsPanel;

import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.core.client.util.Padding;
import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData;
import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer;
import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.HBoxLayoutAlign;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.form.ComboBox;
import com.sencha.gxt.widget.core.client.form.FieldLabel;
import com.sencha.gxt.widget.core.client.form.FormPanel.LabelAlign;

@Singleton
public class ExerciseEditingPage {

	@Inject
	public ExerciseEditingPage(
			ManageMenuGroup group,
			Workspace workspace,
			Factory factory
	) {
		MenuItems.staticPage(
				workspace, 
				group, 
				"Edit Exercises", 
				factory.createWidget()
		);
	}

	public static class Factory {
		
		Messages messages;
		
		@Inject
		public Factory(Messages messages) {
			super();
			this.messages = messages;
		}

		private FormFieldsPanel createWidget() {
			FormFieldsPanel formFieldsPanel = new FormFieldsPanel();
			
			VerticalLayoutContainer vlc = new VerticalLayoutContainer();
			VerticalLayoutData vld = new VerticalLayoutContainer.VerticalLayoutData(1, -1);
			formFieldsPanel.setMainContent(vlc);
			
	        HBoxLayoutContainer c = new HBoxLayoutContainer();
	        c.setPadding(new Padding(5));

	        c.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE);

	        BoxLayoutData flex = new BoxLayoutData(new Margins(0, 5, 0, 0));
	        flex.setFlex(1);
	        c.add(bookField(), flex);
	        c.add(bookField(), flex);
	        c.add(bookField(), flex);

	        BoxLayoutData flex2 = new BoxLayoutData(new Margins(0));
	        flex2.setFlex(1);
	        c.add(bookField(), flex2);		
			
			
	        vlc.add(c, vld);
	        
			return formFieldsPanel;
		}

		private Widget bookField() {
			
			FieldLabel fieldLabel = new FieldLabel(
					new ComboBox<BookProxy>(
							new ListStore<BookProxy>(ModelKeyProviders.longId()),
							LabelProviders.from(BookFields.title)
					),
					messages.book()
			);
			fieldLabel.setLabelAlign(LabelAlign.TOP);
			return fieldLabel;
			
//			HorizontalLayoutContainer hc = new HorizontalLayoutContainer();
//			hc.add(
//					new Label(messages.book()),
//					new HorizontalLayoutData(-1, 1)
//			);
//			hc.add(
//					new ComboBox<Book>(
//							new ListStore<Book>(ModelKeyProviders.longId()),
//							LabelProviders.from(BookFields.title)
//					),
//					new HorizontalLayoutData(1, 1)
//			);
//			return hc;
		}
		
		
	}
	

	
}
